home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1554 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: castle.nando.net!news
  2. From: actuary@nando.net   (Bill McCarthy)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Stupid array problems
  5. Date: 15 Jan 1996 02:00:19 GMT
  6. Organization: News & Observer Public Access
  7. Message-ID: <4dccfj$m95@castle.nando.net>
  8. References: <4d9b9v$14n@paperboy.ids.net> <4dbfd1$2hpc@news.gate.net> <4dc5fv$qdr@newsreader.wustl.edu>
  9. Reply-To: actuary@nando.net (Bill McCarthy)
  10. NNTP-Posting-Host: grail801.nando.net
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <4dc5fv$qdr@newsreader.wustl.edu>, kln@howdy.wustl.edu (Krishnamoorthy Lakshminarayan) writes:
  14. >    Hello:
  15. >
  16. >    Try this:
  17. >
  18. >    void delete_array_element (char **array,  //The array of strings
  19. >                                   int  max,      // total strings in array
  20. >                                   int  num_del)  //index you want deleted
  21. >      {
  22. >      for (int i=max-1; i>num_del; i++) //max-1, because you've deleted
  23. >                                            //one element
  24. >        {
  25. >        array[i] = array[i-1];
  26. >        }
  27. >
  28. >      }
  29.  
  30. This won't compile.  It's not C (you can't declare variables in a
  31. for loop).
  32.  
  33. Try the following function body:
  34.  
  35. if ( max > 0 && num_del < max && num_del >= 0 )
  36. {
  37.   free( array[num_del] ); /* only if malloc'd */
  38.  
  39.   while ( ++num_del < max )
  40.     array[num_del-1] = array[num_del];
  41. }
  42.  
  43. Bill McCarthy
  44. actuary@nando.net
  45. Wendell, NC  USA
  46.  
  47.